package main.java.indi.zyj.sword;

import java.util.HashMap;
import java.util.Map;

public class DismantlingAction1 {

    public int dismantlingAction(String arr) {

        if (arr == null || arr.length() == 0) {
            return 0;
        }

//        char[] charArray = arr.toCharArray();
//        Map<Character, Integer> needs = new HashMap<>();
//        for (int i = 0; i < charArray.length; i++) {
//            needs.
//        }

        Map<Character, Integer> windows = new HashMap<>();
        int left = 0, right = 0, res = 0;

        while (right < arr.length()) {

            char rightChar = arr.charAt(right);
            right++;
            windows.put(rightChar, windows.getOrDefault(rightChar, 0) + 1);

            while (windows.get(rightChar) > 1) {
                char leftChar = arr.charAt(left);
                left++;
                windows.put(leftChar, windows.get(leftChar) - 1);
            }

            res = Math.max(res, right - left);

        }

        return res;

    }



}
